<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( '../global/initialize.php' );

include( "../global/adodb-time.inc.php" );

if( isset( $_GET[ 'type' ] ) && formatInput( $_GET[ 'type' ] ) != '' && isset( $_GET[ 'history_id' ] ) && is_numeric( $_GET[ 'history_id' ] ) ) {
	$type = formatInput( $_GET[ 'type' ] );
	$history_id = formatInput( $_GET[ 'history_id' ] );
	
	if( $type == 'item' ) {
	    $query = "SELECT history_tags.*, history_rating.score AS rating " .
	    		"FROM history_tags " .
	    		"JOIN history_rating ON history_rating.tag_id = history_tags.tag_id " .
	    		"WHERE history_id = $history_id " .
	    		"ORDER BY history_rating.score DESC";
	}
	elseif( $type == 'top20' ) {
	    $query = "SELECT * " .
	    		"FROM history_tags " .
	    		"ORDER BY score DESC LIMIT 20";
	}
	elseif( $type == 'top50' ) {
	    $query = "SELECT * " .
	    		"FROM history_tags " .
	    		"ORDER BY score DESC LIMIT 50";
	}
	else {
	    $query = "SELECT * " .
	    		"FROM history_tags " .
	    		"ORDER BY score DESC LIMIT 100";
	}
	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$num = mysql_numrows( $result );
	$i = 0;
	while ( $i < $num ) {
		if( $i > 0 ) {
			print( ", " );
		}
		
		if( mysql_result( $result, $i, "positive" ) >= mysql_result( $result, $i, "negative" ) ) {
			$positive = "true";
		}
		else {
			$positive = "false";
		}
		
		print( "<a href=\"javascript:void(null);\" onclick=\"selectTag( '" . mysql_result( $result, $i, "tag" ) . "', $positive )\">" . mysql_result( $result, $i, "tag" ) . "</a>" );
		if( $type == 'item' ) {
			$plus = "-";
			if( $positive == 'true' ) {
				$plus = "+";
			}
			print( " ($plus" . number_format( mysql_result( $result, $i, "rating" ) ) . ")" );
		}
		$i ++;
	}
}
?>
